const { Article} = require('../../model/article')

module.exports = async (req,res)=>{

    let page = req.query.page || 1

    let pageSize = 6

    let totle = await Article.countDocuments({})

    let pageNum = Math.ceil(totle / pageSize)

    let result = await Article.find({}).populate('author').skip((page - 1 ) * pageSize).limit(pageSize)
    
    res.render('../views/home/default',{
        articles:result,
        pageNum,
        page
    })
}